package com.gyh.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyh.entity.Course;
import com.gyh.mapper.CourseMapper;
import com.gyh.mapper.RoomMapper;
import com.gyh.service.CourseService;
import com.gyh.vo.CourseVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Resource
    private CourseMapper courseMapper;
    @Resource
    private RoomMapper roomMapper;
    @Override
    public List<Course> getAll() {
        return courseMapper.getAll();
    }

    @Override
    public List<Course> getLatestCourses() {
        return courseMapper.selectLatestCourses();
    }

    @Override
    public List<Course> getPopularCourses() {
        return courseMapper.selectPopularCourses();
    }

    @Override
    public List<Course> getComprehensiveCourses() {
        return courseMapper.selectComprehensiveCourses();
    }

    @Override
    public CourseVo getCourseById(Integer id) {
        Course course = courseMapper.selectById(id);
        CourseVo courseVo = new CourseVo();
        courseVo.setRoomName(roomMapper.selectNameById(course.getRoomId()));
        BeanUtils.copyProperties(course,courseVo);
        return  courseVo ;
    }
}
